﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WoBian.DA.Interface.Admin.SystemSettings;
using WoBian.DA.Interface;
using System.Data;
using WoBian.Entities.Admin;
using WoBian.Common;
namespace WoBian.DA.Oracle.Admin.SystemSettings
{
    public class SystemSettingsDAL:DataAccessBase,ISystemSettingsDAL,IDataAccessLayer
    {

        public System.Data.IDbConnection Connection
        {
            get;
            set;
        }

        public System.Data.IDbTransaction Transaction
        {
            get;
            set;
        }

        public SystemSettingsDAL(IDbConnection connection)
            : base(connection)
        {
            Connection = connection;
        }


        public string GetSystemSettingsValueByKey(string aKeyName)
        {
            string aSql = string.Format(@"SELECT {0} FROM {1} WHERE {2}=:{3} AND ROWNUM = 1"
                , WoBian.Entities.Admin.SystemSettings.KEYVALUE, WoBian.Lib.ConstString.Tables.SYSTEM_SETTINGS
                , WoBian.Entities.Admin.SystemSettings.KEYNAME, WoBian.Entities.Admin.SystemSettings.KEYNAME);
            List<IDataParameter> aList = new List<IDataParameter>();
            aList.Add(AddParameter(WoBian.Entities.Admin.SystemSettings.KEYNAME, aKeyName, DbType.String));
            object obj = ExecuteScaler(aSql, aList);
            return obj.ToNullableString();
        }

        public List<WoBian.Entities.Admin.SystemSettings> GetAllSystemSettings()
        {
            string aSql = string.Format("SELECT * FROM {0}", WoBian.Lib.ConstString.Tables.SYSTEM_SETTINGS);
            IDataReader dr = ExecuteReader(aSql);
            return dr.DataReaderToList<WoBian.Entities.Admin.SystemSettings>();
        }
    }
}
